package com.lczyfz.campusinfo.modules.campusinfoeducation.web;

import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.utils.ApiResultUtils;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.modules.campusinfoeducation.entity.CampusinfoAbroad;
import com.lczyfz.campusinfo.modules.campusinfoeducation.service.CampusinfoAbroadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by yt on 2017/10/24.
 * 出国信息管理 api 接口
 */
@Controller
@RequestMapping(value = "${frontPath}/campusinfoeducation/campusinfoAbroad")
public class CampusinfoAbroadApiController extends BaseController {

    @Autowired
    private CampusinfoAbroadService campusinfoAbroadService;

    /**
     * 分页出国信息管理
     */
    @RequestMapping(value = "abroadList")
    @ResponseBody
    public Map<String, Object> getAbroadList(CampusinfoAbroad campusinfoAbroad, HttpServletRequest request, HttpServletResponse response) {
        Page<CampusinfoAbroad> page = campusinfoAbroadService.findPage(new Page<CampusinfoAbroad>(request, response), campusinfoAbroad);
        Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
        map.put("page", page.getList());
        map.put("pageNo", page.getPageNo());
        map.put("count", page.getCount());
        map.put("totalPage", page.getTotalPage());
        return map;
    }

    /**
     * 添加出国信息
     */
    @RequestMapping(value = "addAbroad")
    @ResponseBody
    public Map<String, Object> addAbroad(CampusinfoAbroad campusinfoAbroad) {
        Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
        if (campusinfoAbroad != null) {
            campusinfoAbroadService.save(campusinfoAbroad);
            map.put("message", "保存出国信息成功");
        } else {
            map.put("message", "保存出国信息失败");
        }
        return map;
    }
}
